<template>
  <div class="c-user__setting">
    <div class="c-user__setting__item">
      <div class="c-martin__label">个人简介: </div>
      <martin-editor v-model="content"
        :options="editorOption"
        class="c-user__editor"
        ref="myQuillEditor">
      </martin-editor>
    </div>
    <div class="c-user__save">
      <martin-button type="primary" @click="saveIntroce">保存</martin-button>
    </div>
  </div>
</template>

<script>
import { quillEditor } from 'vue-quill-editor'

export default {
  name: 'MartinSetting',
  components: {
    'martin-editor': quillEditor
  },
  data() {
    return {
      content: '',
      editorOption: {
        placeholder: '请输入个人简介'
      }
    }
  },
  mounted() {
    this.getInstroce()
  },
  methods: {
    getInstroce() {
      this.$http.get('/user/self').then(({data, status}) => {
        if (status === 200) {
          this.content = data.instroce
        } else this.$message.error('获取个人简介失败')
      }).catch(err => {
        console.log(err)
      })
    },
    saveIntroce() {
      if (this.content) {
        this.$http.post('/user/self', {
          instroce: this.content
        }).then(({data, status}) => {
          if (status === 200) {
            this.$message.success('保存成功')
          }
        }).catch(err => {
          console.log(err)
        })
      } else return void this.$message.error('请填写个人简介')
    }
  }
}
</script>

<style scoped>
.c-user__setting__item {
  float: left;
  width: 100%;
}
.c-user__editor {
  float: left;
  width: 800px;
  height: 200px;
}
.c-user__save {
  margin-top: 150px;
  float: left;
  padding-left: 85px;
}
</style>
